package com.glela.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author liujie
 */
public class ValidateUtil
{
	/**
	 * 校验用户名
	 * 
	 * @param userName
	 * @return
	 */
	public static boolean checkUserName(String userName)
	{
		String regex = "[A-Za-z0-9]{6,12}";//([a-z]|[A-Z]|[0-9]|[\\u4e00-\\u9fa5])+,/^[A-Za-z0-9]{6,12}$/i
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(userName);
		return m.matches();
	}
	
	/**
	 * 校验uuid
	 * 
	 * @param uuid
	 * @return
	 */
	public static boolean checkUUID(String uuid)
	{
		String regex = "[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(uuid);
		return m.matches();
	}
	
	/**
	 * 校验imei
	 * 
	 * @param imei
	 * @return
	 */
	public static boolean checkIMEI(String imei)
	{
		if(imei.equals("000000000000000"))
		{
			return false;
		}
		String regex = "^[0-9]{15}$";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(imei);
		return m.matches();
	}

	public static void main(String[] args)
	{
//		String userName = "sdfdsd.";
//		boolean b = ValidateUtil.checkUserName(userName);
//		System.out.println(b);
		String uuid = "BB853AC9-0F88-4F90-8E04-4EDE0D5A65A8";
		boolean b = ValidateUtil.checkUUID(uuid);
		System.out.println(b);
		String imei = "000000000000000";
		boolean b2 = ValidateUtil.checkIMEI(imei);
		System.out.println(b2);
	}
}
